const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
const WxParse = require('../Common/wxParse/wxParse.js');
Page({
  data: {
    type:1,
    id:'',
    detail:'',
    desc:'',
    isselect:false,
  },
  onLoad(option) {
    if(option.id){
      this.setData({
        id:option.id,
        caseid:option.caseid,
      })
      this.lawyerdetail()
    }
  },
  onShow(){
   
  },
  golink(e){
    var url=e.currentTarget.dataset.url;
    if (!wx.getStorageSync('logintoken')) {
      app.goLogin(false)
      return
    }
    wx.navigateTo({
      url:e.currentTarget.dataset.url
    });
  },
  lawyerdetail(){
    var data={
      lawyerUserId:this.data.id
    }
    Controller.lawyerdetail(data).then(res=>{
      if(res.data.baseData){
        if(res.data.baseData.categoryTitles){
          res.data.baseData.categoryTitles=res.data.baseData.categoryTitles.split(',');
        }
        if(res.data.baseData.qualificationImgUrls){
          res.data.baseData.qualificationImgUrls=res.data.baseData.qualificationImgUrls.split(',');
        }
        this.setData({
          detail:res.data.baseData,
        })
      }
      
    }).catch(res=>{

    })
  },
  preview(event) {
    let currentUrl = event.currentTarget.dataset.src
    wx.previewImage({
      current: currentUrl, // 当前显示图片的http链接
      urls: this.data.detail.qualificationImgUrls // 需要预览的图片http链接列表
    })
  },
  collect(){
    var detail=this.data.detail;
    if(detail.hasLike==1){
      Controller.delAction({
        actionId:detail.likeActionId
      }).then(res=>{
        detail.hasLike=0
        this.setData({
          detail
        })
      })
    }else{
      Controller.action({
        type:1,
        rId:this.data.id,
        contentType:1,
      }).then(res=>{
        wx.showToast({
          title: '点赞成功',
          icon: 'none',
          duration: 1200
        });
        this.lawyerdetail()
      })
    }
    
  },
  select(){
    Controller.selectLawyer({
      lawyerUserId:this.data.id,
      caseInfoId:this.data.caseid
    }).then(res=>{
      wx.navigateBack({ //返回
        delta: 2
      })
      
    })
  },
  onShareAppMessage: function (e) {
    
  },
  onShareTimeline: function(res){
    
  },

})
